using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;


using Material.Object;
using Material.DAL;
namespace Material.Entity
{
	public class TblTransHutangHDREntity
	{
		private Accessor accessor;
		private string connString;

		public TblTransHutangHDREntity (string _connString)
		{
			 this.connString = _connString;
		}

		public int Insert(TblTransHutangHDR tbltranshutanghdr)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransHutangHDR_Insert";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add("@IdTransHDR" ,tbltranshutanghdr.IdTransHDR );
			 accessor.Add("@Nama" ,tbltranshutanghdr.Nama );
			 accessor.Add("@NoHP" ,tbltranshutanghdr.NoHP );
			 accessor.Add("@Alamat" ,tbltranshutanghdr.Alamat );
			 accessor.Add("@TglHutang" ,tbltranshutanghdr.TglHutang );
			 accessor.Add("@TglLunas" ,tbltranshutanghdr.TglLunas );
			 accessor.Add("@JumlahHutang" ,tbltranshutanghdr.JumlahHutang );
			 accessor.Add("@StatusLunas" ,tbltranshutanghdr.StatusLunas );
			 accessor.Add("@Keterangan" ,tbltranshutanghdr.Keterangan );
			 accessor.Add("@CreatedDate" ,tbltranshutanghdr.CreatedDate );
			 accessor.Add("@CreatedBy" ,tbltranshutanghdr.CreatedBy );
			 accessor.Add("@ModifiedDate" ,tbltranshutanghdr.ModifiedDate );
			 accessor.Add("@ModifiedBy" ,tbltranshutanghdr.ModifiedBy );

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public int Update(TblTransHutangHDR tbltranshutanghdr)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransHutangHDR_Update";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransHDR" ,tbltranshutanghdr.IdTransHDR );
			 accessor.Add(@"Nama" ,tbltranshutanghdr.Nama );
			 accessor.Add(@"NoHP" ,tbltranshutanghdr.NoHP );
			 accessor.Add(@"Alamat" ,tbltranshutanghdr.Alamat );
			 accessor.Add(@"TglHutang" ,tbltranshutanghdr.TglHutang );
			 accessor.Add(@"TglLunas" ,tbltranshutanghdr.TglLunas );
			 accessor.Add(@"JumlahHutang" ,tbltranshutanghdr.JumlahHutang );
			 accessor.Add(@"StatusLunas" ,tbltranshutanghdr.StatusLunas );
			 accessor.Add(@"Keterangan" ,tbltranshutanghdr.Keterangan );
			 accessor.Add(@"CreatedDate" ,tbltranshutanghdr.CreatedDate );
			 accessor.Add(@"CreatedBy" ,tbltranshutanghdr.CreatedBy );
			 accessor.Add(@"ModifiedDate" ,tbltranshutanghdr.ModifiedDate );
			 accessor.Add(@"ModifiedBy" ,tbltranshutanghdr.ModifiedBy );

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public int Delete(TblTransHutangHDR tbltranshutanghdr)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransHutangHDR_Delete";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransHDR" ,tbltranshutanghdr.IdTransHDR);

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public TblTransHutangHDR GetDataByID(TblTransHutangHDR tbltranshutanghdr)
		{
			 TblTransHutangHDR result = new TblTransHutangHDR();
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransHutangHDR_SelectByID";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransHDR" ,tbltranshutanghdr.IdTransHDR);

			 SqlDataReader rdr = Excutor.GetDataReader(accessor);
			 if (rdr.HasRows)
			 {
				 while (rdr.Read())
					 {
						 result.IdTransHDR = rdr.GetInt32(0);
						 result.Nama = rdr.GetString(1);
						 result.NoHP = rdr.GetInt32(2);
						 result.Alamat = rdr.GetString(3);
						 result.TglHutang = rdr.GetDateTime(4);
						 result.TglLunas = rdr.GetDateTime(5);
						 result.JumlahHutang = rdr.GetDecimal(6);
						 result.StatusLunas = rdr.GetInt32(7);
						 result.Keterangan = rdr.GetString(8);
						 result.CreatedDate = rdr.GetDateTime(9);
						 result.CreatedBy = rdr.GetString(10);
						 result.ModifiedDate = rdr.GetDateTime(11);
						 result.ModifiedBy = rdr.GetString(12);
					  }
			}
			 return result;
		}

		public List<TblTransHutangHDR> GetDataAll()
		{
			 List<TblTransHutangHDR> result = new List<TblTransHutangHDR>();
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransHutangHDR_SelectAll";
			 accessor.CommandType = CommandType.StoredProcedure;

			 SqlDataReader rdr = Excutor.GetDataReader(accessor);
			 if (rdr.HasRows)
			 {
				 while (rdr.Read())
					 {
						 TblTransHutangHDR obj = new TblTransHutangHDR();
						 obj.IdTransHDR = rdr.GetInt32(0);
						 obj.Nama = rdr.GetString(1);
						 obj.NoHP = rdr.GetInt32(2);
						 obj.Alamat = rdr.GetString(3);
						 obj.TglHutang = rdr.GetDateTime(4);
						 obj.TglLunas = rdr.GetDateTime(5);
						 obj.JumlahHutang = rdr.GetDecimal(6);
						 obj.StatusLunas = rdr.GetInt32(7);
						 obj.Keterangan = rdr.GetString(8);
						 obj.CreatedDate = rdr.GetDateTime(9);
						 obj.CreatedBy = rdr.GetString(10);
						 obj.ModifiedDate = rdr.GetDateTime(11);
						 obj.ModifiedBy = rdr.GetString(12);
						 result.Add(obj);
					  }
			}
			 return result;
		}

	}
}
